home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / DEMO_APP / TODO_LIS.JAV < prev   
Encoding:
Text File  |  1996-10-04  |  3.5 KB  |  118 lines

  1. package sub_arctic.demo_apps;
  2. import sub_arctic.lib.listbox;
  3. import sub_arctic.input.event;
  4. import sub_arctic.input.callback_object;
  5. import sub_arctic.lib.manager;
  6. import sub_arctic.lib.interactor;
  7.  
  8. import java.util.Vector;
  9.  
  10. /**
  11.  * This is a special subclass of the listbox for dealing with our
  12.  * todo list. It is primarly used for handling the special cases of
  13.  * double clicks and drags.
  14.  */
  15. public class todo_listbox extends listbox  implements callback_object{
  16.   /*
  17.    * Ref to the applet.
  18.    */
  19.   protected mail_test _applet;
  20.   /**
  21.    * This class assumes that you will constrain its size and position,
  22.    * so we just give a bogus value to the real listbox knowing you'll
  23.    * override it.
  24.    */
  25.   public todo_listbox(mail_test applet) {
  26.     super(100,100 /*bogus size*/, true /* single selection */, null);
  27.     /* set the callback object to be this ... can't do this in the
  28.        super() call as we can't reference this yet */
  29.     set_callback_obj(this);
  30.     /* set the draggability to true */
  31.     set_allow_dragging(true);
  32.     _applet=applet;
  33.   }
  34.   /** 
  35.    * We got a double click, lets deal with it.
  36.    */
  37.   public void handle_double_click() {
  38.     todo_list_element tle;
  39.     Vector contents;
  40.  
  41.     /* we need to tell that item that we want him to put
  42.        the big message back */
  43.     tle=(todo_list_element)focused_raw();
  44.     /* make sure there is a focused on item... */
  45.     if (tle==null) {
  46.       return;
  47.     }
  48.     tle.restore_message();
  49.     /* now remove him from the list */
  50.     contents=contents_raw();
  51.     contents.removeElement(tle);
  52.     set_contents(contents);
  53.   }
  54.   /**
  55.    * This is called by other parts of the system when they
  56.    * want to insert at an object at a given Y coordinate.
  57.    */
  58.   public void insert_at_point(message msg, int y,int x_store, int y_store) {
  59.     int index,i;
  60.     Vector contents=contents_raw(),new_contents=new Vector();
  61.     todo_list_element tle;
  62.  
  63.     /* build the item */
  64.     tle=new todo_list_element(msg, _applet, x_store, y_store);
  65.     /**
  66.        * Convert Y to an index 
  67.        */
  68.     index=index_for_screen_point(y);
  69.     /* is it out of bounds or the last child? */
  70.     if ((index==-1) ||
  71.     (_child_display.num_children()==index) ||
  72.     (contents.size()==0)) {
  73.       /* just put it on the end */
  74.       contents.addElement(tle);
  75.       set_contents(contents);
  76.       return;
  77.     }
  78.     /* they put it in the middle */
  79.     for (i=0; i<contents.size(); ++i) {
  80.       new_contents.addElement(contents.elementAt(i));
  81.       /* is it our target? */
  82.       if (i==index) {
  83.     new_contents.addElement(tle);
  84.       }
  85.     }
  86.     /* set the contents to their new value */
  87.     set_contents(new_contents);
  88.   }
  89.   public void callback(interactor from_obj, 
  90.                event      evt,
  91.                int        callback_num, 
  92.                Object     callback_info)  {
  93.  
  94.     if (callback_num==listbox.DOUBLE_CLICK) {
  95.       handle_double_click();
  96.     }
  97.     if (callback_num==listbox.DRAG) {
  98.       System.out.println("Handle Drag");
  99.     }
  100.   }
  101. }
  102. /*=========================== COPYRIGHT NOTICE ===========================
  103.  
  104. This file is part of the subArctic user interface toolkit.
  105.  
  106. Copyright (c) 1996 Scott Hudson and Ian Smith
  107. All rights reserved.
  108.  
  109. The subArctic system is freely available for most uses under the terms
  110. and conditions described in 
  111.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  112. and appearing in full in the lib/interactor.java source file.
  113.  
  114. The current release and additional information about this software can be 
  115. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  116.  
  117. ========================================================================*/
  118.